{% extends 'base1.html' %}
{% block title %}用户管理{% endblock %}
{% block content %}
    <div id="content" style="height: 600px">
        <div id="search" class="text-center">
            <form class="form-inline" action="{% url 'user:search' %} " method="post">
                <div class="form-group ">
                    <a class="btn btn-info" href="{% url 'user:add' %}">添加</a>
                </div>
                {% csrf_token %}
                <div class="form-group">
                    <label for="id">ID</label>
                    <input type="text" class="form-control" id="id" name="id" placeholder="输入ID查询">
                </div>
                <div class="form-group">
                    <label for="username">用户名</label>
                    <input type="text" class="form-control" id="username" name="username" placeholder="输入用户名查询">
                </div>
                <div class="form-group">
                    <label for="name">姓名</label>
                    <input type="text" class="form-control" id="name" name="name" placeholder="输入姓名查询">
                </div>
                <div class="form-group">
                    <label for="role">角色</label>
                    <select id="role" name="role" class="form-control" style="width: 200px">
                        <option style='display: none'></option>
                        <option>管理员</option>
                        <option>操作员</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-success">查询</button>
            </form>
        </div>
        <br>
        <div id="table" align="center">
            {% if result %}
                <table class="table table-striped table-bordered table-hover  table-condensed" style="width: 1100px">
                <tr class="success">
                    <td>ID</td>
                    <td>用户名</td>
                    <td>密码</td>
                    <td>姓名</td>
                    <td>角色</td>
                    <td>创建时间</td>
                    <td>修改时间</td>
                    <td>编辑</td>
                    <td>删除</td>
                </tr>
                {% for foo in result %}
                    <tr>
                        <td>{{ foo.id }}</td>
                        <td>{{ foo.username }}</td>
                        <td>{{ foo.password }}</td>
                        <td>{{ foo.name }}</td>
                        <td>{{ foo.role }}</td>
                        <td>{{ foo.create_time }}</td>
                        <td>{{ foo.modify_time }}</td>
                        <td><a class="btn btn-primary btn-sm" href="{% url 'user:update' foo.id %}">编辑</a></td>
                        <td><a class="btn btn-danger btn-sm" href="{% url 'user:delete' foo.id %}">删除</a></td>
                    </tr>
                {% endfor %}
            {% else %}
                <p>没有任何用户</p>
            {% endif %}
            </table>
        </div>
        <!-- 分页开始 -->
        <div class="text-center">
            <ul class="pagination">
                <li><a href="/user/?page=1" rel="external nofollow">首页</a></li>
                {% if result.has_previous %}
                    <li><a href="/user/?page={{ result.previous_page_number }}" rel="external nofollow">上一页</a></li>
                {% endif %}
                {% for num in result.paginator.page_range %}
                    <li><a href="/user/?page={{ num }}" rel="external nofollow">{{ num }}</a></li>
                {% endfor %}
                {% if result.has_next %}
                    <li><a href="/user/?page={{ result.next_page_number }}" rel="external nofollow">下一页</a></li>
                {% endif %}
                <li><a href="/user/?page={{ result.paginator.num_pages }}" rel="external nofollow">尾页</a></li>
            </ul>
        </div>
        <!-- 分页结束 -->
    </div>
{% endblock %}